package io.sdph.controller;

import io.sdph.userprofile.ISessionManager;
import io.sdph.userprofile.IUserManager;
import io.sdph.userprofile.exceptions.UserProfileException;
import io.sdph.userprofile.model.User;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;


/**
 * Servlet odpowiedzialny za mozliwosc usuniecia uzytkownika w panelu przedstawiciela handlowego (admin.jsp)
 *
 * @author MODUL FRONTU (WWW)
 */
@Controller
@RequestMapping("/admin/DeleteUser")
public class AdminDeleteUser {
       
        private static final String SELECTED_USER = "users";
        private static final String ANOTHER = "all";
       
        private static final String PAGE_VIEW = "admin";

        /** Komponent pomocniczy do zarz�dzania sesj� u�ytkownika. */
        @Autowired
        ISessionManager sessionManager;
        
        @Autowired
        IUserManager userManager;
       
        //HttpServletRequest arg0, HttpServletResponse arg1
        @RequestMapping(method=RequestMethod.GET)
        public ModelAndView showPage() throws Exception {
               
                ModelAndView model = new ModelAndView(PAGE_VIEW);
                model.addObject("pageName", "user");
                return model;
        }
       
        @RequestMapping(method=RequestMethod.POST)
        public ModelAndView adminDeleteUser(
                        @RequestParam(SELECTED_USER) final String selectedUser                    
        				) {
               
                ModelAndView model = new ModelAndView(PAGE_VIEW);
                            
                try {
					userManager.deleteUser(new User(selectedUser));
				} catch (UserProfileException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
                model.addObject("pageName", "user");
                return model;
        }
       
}
